import { Dict, DictType, getDictList } from "@/utils/cacheUtil";
import { defineComponent } from "vue";
import "./status.scss";
export default defineComponent({
	props: {
		modelValue: [String, Boolean, Number]
	},
	emits: [],
	setup(props) {
		const typeList = ref([] as Dict[]);
		const colorType = {
			running: "green",
			pulling: "orange",
			stopping: "orange",
			pulled: "orange",
			downloading: "orange",
			downloaded: "orange"
		} as { [key: string]: string };
		onMounted(() => {
			initPage();
		});
		const initPage = () => {
			getDictList(DictType.ServiceStatus).then(list => {
				typeList.value = list;
			});
		};
		const getBody = () => {
			let info = typeList.value.find(item => item.key == props.modelValue);
			return (
				<span class="status-info">
					<span class="dot" style={{ background: colorType[props.modelValue + ""] || "red" }} />
					<span>{info?.label || props.modelValue || "未安装"}</span>
				</span>
			);
		};
		return () => {
			return getBody();
		};
	}
});
